//index.js
//获取应用实例
var app = getApp()
Page({
    data: {
    
        tabArr: {
            curHdIndex: 0,
            curBdIndex: 0
        },
        currentTab: 0,


    },

    onLoad: function (options) {
        var $that = this;
        $that.getProbitList();
      
    },

    bindKeyInput: function (e) {
        var $that = this;
        var value = e.detail.value;
       
        console.log(value);
        $that.setData({
            keyword: value
        });
        console.log($that.data.keyword);

    },
 
    //事件处理函数
    tabFun: function (e) {
        var $that = this;
        //获取触发事件组件的dataset属性  
        var _datasetId = e.target.dataset.id;
        var _obj = {};
        _obj.curHdIndex = _datasetId;
        _obj.curBdIndex = _datasetId;
        this.setData({
            tabArr: _obj
        });
        console.log(_obj.curHdIndex);
        console.log(_obj.curBdIndex);
    
    },
    //事件处理函数
    bindViewTap: function () {
        wx.navigateTo({
            url: '../detail/index'
        })
    },
    tongbutuiguang:function(){
        var memberinfo = wx.getStorageSync('memberinfo');
        var $that = this;
      //  console.log(e);
        app.util.request({
            url: 'entry/wxapp/SyncProbit',
            data: {
               // page:1,
                "m": 'nets_haojk',
                //state:e.currentTarget.dataset.state
                memberid: memberinfo.memberid

           
            },
            method: 'post',
            success: function (response) {
                console.log(response);
                var obj = response.data;
              
                if(obj.errno==0){
                        //同步成功
                     $that.getProbitList();
                        //$that.setData({tuiguangList:obj.data});

                    
                }
            }
        })
    },
    getProbitList:function(e){
        var memberinfo = wx.getStorageSync('memberinfo');
        var $that = this;
        console.log(e);
        //发送的类别参数
        var pstate = '';
        if (!e || e.currentTarget.dataset.state == " "){
                pstate ="";
                console.log("全部");
        } else if (e.currentTarget.dataset.state == "1"){
            console.log("进入已用");
            pstate = 1;
        } else if (e.currentTarget.dataset.state == "0"){
            console.log("进入未用");
            pstate =0; 
        }
       
       //是否传搜索的参数
        var keyword ="";
        if (!e || e.currentTarget.dataset.keyword == " ") {
            keyword = "";
            console.log("没有搜索1");
        } else if (e.currentTarget.dataset.keyword == "1"){
            keyword=$that.data.keyword;
        }else{
            keyword = "";
            console.log("没有搜索2");
        }

        app.util.request({
            url: 'entry/wxapp/GetProbitList',
            data: {
                "m": 'nets_haojk',
                memberid: memberinfo.memberid,
                pstate: pstate,
                keyword:keyword
          
            },
            method: 'post',
            success: function (response) {
                console.log(response);
                console.log(response.data.errno);
                if(response.data.errno==0){
                    var obj = response.data.data;
                    console.log(obj);
                    //循环转时间格式
                    for (var i = 0; i < obj.list.length; i++) {
                        obj.list[i].created_at = form_time(obj.list[i].created_at);
                      
                    }
                    $that.setData({
                        tuiguangList: obj.list,
                        usecount: obj.usecount,
                        totalcount: obj.totalcount,
                    })
                     
                }
               
                //int转时间戳
                function form_time(a) {
                    var myDate = new Date(parseInt(a) * 1000);
                    var datestr = "";
                    datestr = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
                    datestr = datestr + "-" + (myDate.getMonth() + 1);       //获取当前月份(0-11,0代表1月)
                    datestr = datestr + "-" + myDate.getDate();        //获取当前日(1-31)
                    datestr = datestr + " " + myDate.getHours();  
                    datestr = datestr + ":" + myDate.getMinutes();  
                    datestr = datestr + ":" + myDate.getSeconds();  
                    return datestr;
                }
                
            }
        }) 
    },

})
